package com.shj.controller;

import com.shj.entity.S201;
import com.shj.entity.SysMedical;
import com.shj.service.S201Service;
import com.shj.service.SysMedicalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/system/medical")
public class SysMedicalController {

    @Autowired
    private SysMedicalService sysMedicalService;
    @Autowired
    private S201Service s201Service;

    @RequestMapping("/list")
    public String findAll(Model model) {
        List<SysMedical> list = sysMedicalService.findAll();
        model.addAttribute("list", list);
        return "medical/medical_list";
    }

    @RequestMapping("/openAdd")
    public String openAdd(Model model) {
        List<S201> s20102List=s201Service.findListByType("02");
        List<S201> s20106List=s201Service.findListByType("06");
        List<S201> s20104List=s201Service.findListByType("04");
        List<S201> s20101List=s201Service.findListByType("01");
        List<S201> s2010301List=s201Service.findListByType("03");
        List<S201> s2010302List=s201Service.findListByType("0301");

        model.addAttribute("s20102List", s20102List);
        model.addAttribute("s20106List", s20106List);
        model.addAttribute("s20104List", s20104List);
        model.addAttribute("s20101List", s20101List);
        model.addAttribute("s2010301List", s2010301List);
        model.addAttribute("s2010302List", s2010302List);

        return "medical/medical_add";
    }

    @RequestMapping("/add")
    public String add(Model model, SysMedical sysMedical) {
        sysMedicalService.add(sysMedical);
        return findAll(model);
    }

    @RequestMapping("/openEdit")
    public String openEdit(Model model, String id) {
        List<S201> s20102List=s201Service.findListByType("02");
        List<S201> s20106List=s201Service.findListByType("06");
        List<S201> s20104List=s201Service.findListByType("04");
        List<S201> s20101List=s201Service.findListByType("01");
        List<S201> s2010301List=s201Service.findListByType("03");
        List<S201> s2010302List=s201Service.findListByType("0301");

        model.addAttribute("s20102List", s20102List);
        model.addAttribute("s20106List", s20106List);
        model.addAttribute("s20104List", s20104List);
        model.addAttribute("s20101List", s20101List);
        model.addAttribute("s2010301List", s2010301List);
        model.addAttribute("s2010302List", s2010302List);

        SysMedical sysMedical = sysMedicalService.queryById(id);
        model.addAttribute("medical", sysMedical);
        return "medical/medical_edit";
    }

    @RequestMapping("/edit")
    public String edit(Model model, SysMedical sysMedical) {
        sysMedicalService.edit(sysMedical);
        return findAll(model);
    }

    @RequestMapping("/delete")
    public String delete(Model model, String id) {
        sysMedicalService.delete(id);
        return findAll(model);
    }

}
